package com.gouqi.tools.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gouqi.gouqitoolscommon.model.entity.Tool;
import com.gouqi.gouqitoolscommon.service.InnerToolService;
import com.gouqi.tools.common.ErrorCode;
import com.gouqi.tools.exception.BusinessException;
import com.gouqi.tools.mapper.ToolMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

@DubboService
public class InnerToolServiceImpl implements InnerToolService {

    @Resource
    private ToolMapper toolMapper;

    @Override
    public Tool getTool(String url, String method) {
        //参数校验
        if (StringUtils.isAnyBlank(url, method)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        //创建查询条件包装器
        QueryWrapper<Tool> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("url", url);
        queryWrapper.eq("method", method);
        return toolMapper.selectOne(queryWrapper);
    }
}
